/* * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Controller;

import java.io.File;
import Model.RuleChecker;


/**
 *
 * @author Sinem
 */
public class RuleController {
    
    public RuleController()
    {
    }
    
    public boolean checkAllFiles(String sURL)
    {
        boolean bAllFilesChecked = false;        

        File[] allFiles = new File(sURL).listFiles();

        RuleChecker checker = new RuleChecker();
        Thread ruleCheckerThread = new Thread(checker);

        for(File file: allFiles)
        {
          if(file.isFile() == true)
          {
            //if it is a file to be controlled add, otherwise ignore
            if((file.getName().contains(".htm")) || (file.getName().contains(".html")) ||
                    (file.getName().contains(".asp")) || (file.getName().contains(".aspx")) ||
                    (file.getName().contains(".css")) || (file.getName().contains(".php")) ||
                    (file.getName().contains(".ashx")) || (file.getName().contains(".cfm")))
            {
                checker.addFileToBeChecked(file.getAbsolutePath());
            }
          }
          if(file.isDirectory())
            checkAllFiles(file.getAbsolutePath());
        }

        ruleCheckerThread.start();

         try {  
           ruleCheckerThread.join();
         } catch(InterruptedException e)
           { System.err.println("Thread Interrupted");}
        
        bAllFilesChecked = true;

        return bAllFilesChecked;
        
    }
}
